#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：django32_celery 
@File    ：last_list_file.py
@IDE     ：PyCharm 
@Author  ：Toby
@Date    ：2024/4/20 15:52 
'''

import os


def get_latest_file(directory):
    latest_file = None
    latest_mtime = 0
    for file in os.listdir(directory):
        file_path = os.path.join(directory, file)
        if os.path.isfile(file_path) and os.path.getmtime(file_path) > latest_mtime:
            latest_file = file_path
            latest_mtime = os.path.getmtime(file_path)
    return latest_file


if __name__ == '__main__':
    current_dir = os.getcwd()
    print(current_dir)

    # directory = '/path/to/your/folder'  # 替换为你的文件夹路径
    latest_file = get_latest_file(current_dir)
    if latest_file:
        print(f"The latest file is: {latest_file}")
        print(f"Last modified time: {os.path.getmtime(latest_file)}")
    else:
        print("No files found in the directory.")